const program = require("commander");
const chalk = require("chalk");
const creteTemplateCommands = require("./template");
/**
 * 创建的命令
 */
const creteCommands = () => {
  // // 创建模板
  program
  .command('create')
  .argument("[project-name]", "project name", validatAppName)
  .description("create a new project powered by waitkey-cli")
  .option('-t, --template [template]', 'Template to use (vue, react) default vue')
  .action(creteTemplateCommands);

};

 /**
  * @description 校验项目名称
  * @param {String} projectName 项目名称
  * @returns projectName
  */
 function validatAppName(projectName) {
  var reg = /^[a-zA-Z][-_a-zA-Z0-9]/;
  if (!reg.test(projectName)) {
    throw new program.InvalidArgumentError(
      chalk.red(`${projectName}项目名称必须以字母开头且长度大于2，请重新输入！`)
    );
  }
  return projectName;
}

module.exports = creteCommands;
